﻿using Microsoft.Extensions.Options;
using Prometheus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static IdentityModel.ClaimComparer;

namespace Ebusiness_Framework.ResourcesMonitoring
{
    /// <summary>
    /// 资源监控
    /// </summary>
    public class ResourcesMoniters
    {
        //private IOptions<ResourcesMoniterOptions> options;

        /// <summary>
        /// 1、先创建Counter
        /// </summary>
        private Counter _requestCounter;

        public ResourcesMoniters(IOptions<ResourcesMoniterOptions> _options)
        {
            ResourcesMoniterOptions resourcesMoniterOptions = _options.Value;
            _requestCounter = Metrics.CreateCounter(resourcesMoniterOptions.CounterName, resourcesMoniterOptions.CounterHelp, new CounterConfiguration
            {
                LabelNames = resourcesMoniterOptions.CounterLabelNames
            });
        }

        /// <summary>
        /// 资源监控方法
        /// </summary>
        /// <param name="methodType"></param>
        /// <param name="addres"></param>
        public void ResourcesCounter(string methodType, string addres)
        {
            _requestCounter.WithLabels(methodType, addres).Inc();
        }
    }
}
